package com.guigu.dh.listener;


import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.guigu.dh.mapper.DictMapper;
import com.guigu.dh.pojo.cmn.Dict;
import com.guigu.dh.vo.cmn.DictExcelVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;

import java.util.Map;

@Slf4j
public class DictImportDataListener extends AnalysisEventListener<DictExcelVO> {

    private DictMapper dictMapper;

    public DictImportDataListener(DictMapper dictMapper) {
        this.dictMapper = dictMapper;
    }

    @Override
    public void invoke(DictExcelVO o, AnalysisContext analysisContext) {
        Dict dict = new Dict();
        dict.setId(Long.valueOf(o.getId()));
        dict.setName(o.getName());
        dict.setParentId(Long.valueOf(o.getParentId()));
        dict.setValue(o.getValue());
        dict.setDictCode(o.getDictCode());
        dictMapper.insert(dict);
    }

    @Override
    public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
        // 表头信息
        // System.out.println(headMap);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        //System.out.println("执行了");
    }

}
